<template>
  <div>
    <div class="second">
      <!-- 传承之路 -->
      <div class="heritageroad">
        <!-- 标题 -->
        <div class="title">
          <h3>传承之路</h3>
          <h3 @click="goDetail('heritageroad')">更多>></h3>
        </div>
        <!-- 内容 -->
        <div class="content">
          <!-- <div class="left" @click="moveleft">&lt;</div> -->
          <div class="mid" ref="mid">
            <div class="sl" :style="scrollLeft">
              <a
                v-for="(item ,index) in cczl"
                style="margin-right:50px"
                @click="showDetailcczr(item.id)"
                @mouseover="mouseover(index)"
                @mouseout="mouseout(index)"
              >
                <img @click="goHeritageRoad(item.id)" :src="item.zpurl" alt />
                <span
                  :class="active == index ? 'addclass' : '' "
                  @click="goHeritageRoad(item.id)"
                >{{item.name}}</span>
              </a>
              <!-- <a
                v-for="(item ,index) in cczl"
                style="margin-right:50px"
                @click="showDetailcczr(item.id)"
                @mouseover="mouseover(index)"
                @mouseout="mouseout(index)"
              >
                <img :src="item.zpurl" alt />
                <span :class="active == index ? 'addclass' : '' ">{{item.name}}</span>
              </a>-->
            </div>
          </div>

          <!-- <div class="left" @click="moveright">&gt;</div> -->
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Swiper from "swiper";
import "swiper/dist/css/swiper.min.css";

export default {
  data() {
    return {
      cczl: [],
      scrollLeft: {
        left: "0px",
      },
      timer: null,
      flag: true,
      active: -1,
    };
  },
  created() {
    this.getMenulist();
  },
  mounted() {
    this.timer = setInterval(() => {
      if (this.flag) {
        this.get();
      }
    }, 50);

    // console.log('1111',window.getComputedStyle(this.$refs.mid).width);
  },
  updated() {
    // leftSlid(".mid .sl");
  },
  methods: {
    // 点击详情跳转到传承之路
    goDetail(r) {
      this.$router.push({ path: "/" + r });
    },
    //获取轮播图
    getMenulist() {
      this.$axios
        .get("TCM/GetFirstPage")
        .then((res) => {
          if (res.status == 200) {
            this.cczl = res.data.cczl;
            let doubule=res.data.cczl;
            this.cczl.push(...doubule);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    get() {
      this.scrollLeft.left = parseInt(this.scrollLeft.left) - 1 + "px";
      if (parseInt(this.scrollLeft.left) < -900) {
        this.scrollLeft.left = "-100px";
      }
    },
    // 鼠标经过悬停
    mouseover(index) {
      this.flag = false;
      this.active = index;
      // clearInterval(this.timer);
    },
    // 鼠标离开继续滚动
    mouseout(index) {
      this.flag = true;
      this.active = index;
      // setInterval(this.get, 50);
    },
    //跳转
    showDetailcczr(index, item) {
      this.active = index;
    },
    // 点击左箭头左移动
    moveleft() {
      // this.flag = false;
      if (this.scrollLeft.left == 0) {
        // this.disabled1 = true;
      } else {
        this.scrollLeft.left = parseInt(this.scrollLeft.left) - 100 + "px";
      }
    },
    // 点击右箭头右移动
    moveright() {
      console.log(this.scrollLeft.left);
      // this.flag = false;
      if (this.scrollLeft.left > "200px") {
        // this.disabled2 = false;
        this.scrollLeft.left = 0 + "px";
      } else {
        this.scrollLeft.left = parseInt(this.scrollLeft.left) + 100 + "px";
      }
    },
    // 跳转到传承之路详情页
    goHeritageRoad(id) {
      this.$router.push({ path: `/heritageroadDetail/${id}` });
    },
  },
};
</script>

<style lang="less">
// 第二行
.second {
  margin-top: 20px;
  height: 250px;
  border: 0.5px solid #ebe4d9;
  border-top: none;

  .content {
    height: 190px;
    padding: 20px 0;
    display: flex;
    justify-content: space-between;
    .left {
      width: 130px;
      height: 190px;
      // height: 100%;
      line-height: 160px;
      font-size: 100px;
      font-weight: bold;
      text-align: center;
      color: #aaaaaa;
      cursor: pointer;
    }
    .mid {
      width: 1200px;
      position: relative;
      overflow: hidden;
      text-align: center;
      // padding-left:-100px;
      .sl {
        position: absolute;
        // left: -100px;
        top: 0;
        // width: 100%;
        height: 190px;
        display: flex;
        justify-content: flex-start;
        a {
          // position: absolute;
          // float: left;
          cursor: pointer;
          display: block;
          height: 160px;
          img {
            height: 150px;
          }
          span {
            cursor: pointer;
            padding-top: 10px;
            display: block;
          }
        }
      }
    }
  }
  .addclass {
    color: red;
  }
}
</style>